<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="5" :lg="7" :md="8" :sm="24">
            <a-form-item label="所属系统">
              <!-- <a-input placeholder="请输入所属系统" v-model="queryParam.belongSystem"></a-input> -->
              <a-select show-search @focus="isBelongSystem" style="width: 100%" placeholder="请选择系统"
                v-model="queryParam.belongSystem" allowClear>
                <a-select-option v-for="(item, index) in belongSystems" :key="index" :value="item.value">
                  {{ item.value }}
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :xl="5" :lg="7" :md="8" :sm="24">
            <a-form-item label="问题类型">
              <!-- <a-input placeholder="请输入问题类型" v-model="queryParam.problemType"></a-input> -->
              <a-select show-search @focus="isProblemType" style="width: 100%" placeholder="请选择问题类型"
                v-model="queryParam.problemType" allowClear>
                <a-select-option v-for="(item, index) in problemTypes" :key="index" :value="item.value">
                  {{ item.value }}
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :xl="5" :lg="7" :md="8" :sm="24">
            <a-form-item label="反馈部门">
              <a-input placeholder="请输入反馈部门" v-model="queryParam.feedbackDepartment"></a-input>
              <!-- <a-select show-search @focus="isProblemType" style="width: 100%" placeholder="请选择问题类型"
                v-model="queryParam.problemType" allowClear>
                <a-select-option v-for="(item, index) in problemTypes" :key="index" :value="item.value">
                  {{ item.value }}
                </a-select-option>
              </a-select> -->
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            
            <a-col :xl="5" :lg="7" :md="8" :sm="24">
              <a-form-item label="问题状态">
                <!-- <a-input placeholder="请输入问题描述" v-model="queryParam.problemDesc"></a-input> -->
                <a-select show-search style="width: 100%" placeholder="请选择问题类型"
                v-model="queryParam.status" allowClear>
                <a-select-option v-for="(item, index) in statuss" :key="index" :value="item.value">
                  {{ item.value }}
                </a-select-option>
              </a-select>
              </a-form-item>
            </a-col>
            <a-col :xl="5" :lg="7" :md="8" :sm="24">
              <a-form-item label="问题描述">
                <a-input placeholder="请输入问题描述" v-model="queryParam.problemDesc"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="10" :lg="11" :md="12" :sm="24">
              <a-form-item label="反馈日期">
                <a-date-picker :show-time="true" format="YYYY-MM-DD" placeholder="请选择开始时间" :disabled-date="disabledStartDate"
                  class="query-group-cust" v-model="queryParam.feedbackDate_begin"></a-date-picker>
                <span class="query-group-split-cust"></span>
                <a-date-picker :show-time="true" format="YYYY-MM-DD" placeholder="请选择结束时间" :disabled-date="disabledEndDate"
                  class="query-group-cust" v-model="queryParam.feedbackDate_end"></a-date-picker>
              </a-form-item>
            </a-col>
            <a-col :xl="5" :lg="7" :md="8" :sm="24">
              <a-form-item label="提问人">
                <a-input placeholder="请输入提问人" v-model="queryParam.questioner"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="5" :lg="7" :md="8" :sm="24">
              <a-form-item label="反馈人">
                <a-input placeholder="请输入提问人" v-model="queryParam.assigner"></a-input>
              </a-form-item>
            </a-col>
            
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch('需求反馈')" style="margin-left: 8px">
                {{ toggleSearchStatus ? '展开' : '收起' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('需求反馈')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl"
        @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <!-- 高级查询区域 -->
      <!-- <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query> -->
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel">
            <a-icon type="delete" />删除
          </a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作
          <a-icon type="down" />
        </a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{
            selectedRowKeys.length
        }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table ref="table" size="middle" bordered rowKey="id" class="j-table-force-nowrap" :scroll="{ x: true }"
        :columns="columns" :dataSource="dataSource" :pagination="ipagination" :loading="loading"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }" @change="handleTableChange">

        <!-- 反馈状态插槽 -->
        <template slot="status" slot-scope="text">
          <a-tag v-if="text == '未开始'" color="red">未开始</a-tag>
          <a-tag v-if="text == '进行中'" color="orange">进行中</a-tag>
          <a-tag v-if="text == '已完成'" color="blue">已完成</a-tag>
          <a-tag v-if="text == '已关闭'">已关闭</a-tag>
        </template>

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>

        <template slot="imgSlot" slot-scope="text,record">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" :preview="record.id" height="25px" alt=""
            style="max-width:80px;font-size: 12px;font-style: italic;" />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a v-if="record.status !='已关闭'" @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多
              <a-icon type="down" />
            </a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <ch-demand-feedback-modal ref="modalForm" @ok="modalFormOk" />
  </a-card>
</template>

<script>
import { getAction, postAction } from '@/api/manage'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import ChDemandFeedbackModal from './modules/ChDemandFeedbackModal'
import '@/assets/less/TableExpand.less'

export default {
  name: "ChDemandFeedbackList",
  mixins: [JeecgListMixin],
  components: {
    ChDemandFeedbackModal
  },
  data() {
    return {
      //子表options
      options: [],
      //所属系统
      belongSystems:[],
      //问题类型
      problemTypes:[],
      //问题状态
      statuss:[
        {
          index:1,
          value:'未开始',
        },
        {
          index:2,
          value:'进行中',
        },
        {
          index:3,
          value:'已完成',
        },
        {
          index:4,
          value:'已关闭',
        },
      ],
      description: '需求反馈管理页面',
      toggleSearchStatus: true,
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '所属系统',
          align: "center",
          dataIndex: 'belongSystem'
        },
        {
          title: '反馈部门',
          align: "center",
          dataIndex: 'feedbackDepartment'
        },
        {
          title: '提问人',
          align: "center",
          dataIndex: 'questioner'
        },
        {
          title: '问题类型',
          align: "center",
          dataIndex: 'problemType'
        },
        {
          title: '问题描述',
          align: "center",
          dataIndex: 'problemDesc',
          scopedSlots: { customRender: 'htmlSlot' }
        },
        {
          title: '解决方案',
          align: "center",
          dataIndex: 'solution',
          scopedSlots: { customRender: 'htmlSlot' }
        },
        {
          title: '附件',
          align: "center",
          dataIndex: 'enclosure',
          scopedSlots: { customRender: 'fileSlot' }
        },
        {
          title: '指派人',
          align: "center",
          dataIndex: 'assigner'
        },
        {
          title: '反馈日期',
          align: "center",
          dataIndex: 'feedbackDate'
        },
        {
          title: '反馈状态',
          align: "center",
          dataIndex: 'status',
          scopedSlots: { customRender: 'status' },
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: "center",
          fixed: "right",
          width: 147,
          scopedSlots: { customRender: 'action' },
        }
      ],
      url: {
        list: "/ch/chDemandFeedback/list",
        delete: "/ch/chDemandFeedback/delete",
        deleteBatch: "/ch/chDemandFeedback/deleteBatch",
        exportXlsUrl: "/ch/chDemandFeedback/exportXls",
        importExcelUrl: "ch/chDemandFeedback/importExcel",
        queryDistListByCode: '/ch/chSysProblemAllocation/queryDistListByCode', //系统问题分配-查询字典列表（系统名称、问题类型）
        queryLoginUsersByDeptId: '/ch/chSysProblemAllocation/queryLoginUsersByDeptId' //查询IT部的所有员工信息

      },
      dictOptions: {},
      superFieldList: [],
    }
  },
  created() {
    this.getSuperFieldList();
    // 指派人获取焦点事件
    this.handleFocusAssigner()
    console.log("this.toggleSearchStatus", this.toggleSearchStatus);
  },
  mounted() {
    if (localStorage.getItem('news2')) {
      this.handleEdit(JSON.parse(localStorage.getItem('news2')))
    }
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    }
  },
  methods: {
    // 开始时间禁用
    disabledStartDate(startValue){
      console.log("startValue",startValue);
      const endValue = this.queryParam.feedbackDate_end;
      if (!startValue || !endValue) {
        return false;
      }
      return startValue.valueOf() > endValue.valueOf();
    },
    //结束时间禁用
    disabledEndDate(endValue) {
      const startValue = this.queryParam.feedbackDate_begin
      if (!endValue || !startValue) {
        return false;
      }
      return startValue.valueOf() >= endValue.valueOf();
    },
    // 获取系统名称,问题类型
    isBelongSystem(){
      getAction(this.url.queryDistListByCode).then(res => {
        console.log("queryDistListByCode--res", res);
        if (res.code == 200) {
          this.belongSystems = res.result.system_code
          this.problemTypes = res.result.problem_type
          // this.$emit('systemNames', res.result.system_code)
          // this.$emit('problemTypes', res.result.problem_type)
          // if (res.result.system_code.length > 0 || res.result.problem_type.length >0) {
          //     localStorage.setItem('systemNames',JSON.stringify(res.result.system_code))
          //     localStorage.setItem('problemTypes',JSON.stringify(res.result.problem_type))
        }
      })
    },
    isProblemType(){
      getAction(this.url.queryDistListByCode).then(res => {
        console.log("queryDistListByCode--res", res);
        if (res.code == 200) {
          // this.systemNames = res.result.system_code
          this.problemTypes = res.result.problem_type
          // this.$emit('systemNames', res.result.system_code)
          // this.$emit('problemTypes', res.result.problem_type)
          // if (res.result.system_code.length > 0 || res.result.problem_type.length >0) {
          //     localStorage.setItem('systemNames',JSON.stringify(res.result.system_code))
          //     localStorage.setItem('problemTypes',JSON.stringify(res.result.problem_type))
        }
      })
    },
    //获取问题状态
    // isProblemDesc(){
    //   getAction(this.url.queryDistListByCode).then(res => {
    //     })
    // },
    // 指派人获取焦点事件
    handleFocusAssigner() {
      getAction('/ch/chSysProblemAllocation/queryLoginUsersByDeptId').then((res) => {
        if (res.code == 200) {
          let _this = this
          res.result.forEach(function (value, key) {
            var obj = {}
            obj.text = value.realname
            obj.value = value.realname
            _this.options.push(obj)
            // console.log("this",this);
            console.log(value.realname, key)
          })
          console.log('this.options', this.options)
          localStorage.setItem('options', JSON.stringify(this.options))
          console.log("999", JSON.parse(localStorage.getItem('options')));

        }
        console.log('queryLoginUsersByDeptId--res', res)
      })
    },
    // handleAdd(){
    //   console.log("handleAdd");
    // },
    handleToggleSearch() {
      this.toggleSearchStatus = !this.toggleSearchStatus;
    },
    initDictConfig() {
    },
    getSuperFieldList() {
      let fieldList = [];
      fieldList.push({ type: 'string', value: 'belongSystem', text: '所属系统', dictCode: '' })
      fieldList.push({ type: 'string', value: 'feedbackDepartment', text: '反馈部门', dictCode: '' })
      fieldList.push({ type: 'string', value: 'questioner', text: '提问人', dictCode: '' })
      fieldList.push({ type: 'string', value: 'problemType', text: '问题类型', dictCode: '' })
      fieldList.push({ type: 'Text', value: 'problemDesc', text: '问题描述', dictCode: '' })
      fieldList.push({ type: 'Text', value: 'solution', text: '解决方案', dictCode: '' })
      fieldList.push({ type: 'Text', value: 'enclosure', text: '附件', dictCode: '' })
      fieldList.push({ type: 'string', value: 'assigner', text: '指派人', dictCode: '' })
      fieldList.push({ type: 'datetime', value: 'feedbackDate', text: '反馈日期' })
      fieldList.push({ type: 'int', value: 'status', text: '反馈状态(1.未开始2.进行中3.已完成4.关闭)', dictCode: '' })
      this.superFieldList = fieldList
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>